package com.ruoyi.project.hit.controller;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hit.domain.SystemDict;
import com.ruoyi.project.hit.service.SystemDictService;
import com.ruoyi.project.system.domain.SysPost;
import com.ruoyi.project.system.service.ISysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员等级信息操作处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/hit/dict")
public class SysDictController extends BaseController
{
    @Autowired
    private SystemDictService systemDictService;

    /**
     * 获取会员等级列表
     */
    //@PreAuthorize("@ss.hasPermi('system:post:list')")
    @GetMapping("/list")
    public TableDataInfo list(SystemDict dict)
    {
        startPage();
        List<SystemDict> list = systemDictService.selectDictList(dict);
        return getDataTable(list);
    }

    /**
     * 删除会员等级
     */
   // @PreAuthorize("@ss.hasPermi('system:post:remove')")
    @Log(title = "会员等级管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id)
    {

        return toAjax(systemDictService.deleteDictById(id));
    }


//    @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('system:post:export')")
//    @GetMapping("/export")
//    public AjaxResult export(SysPost post)
//    {
//        List<SysPost> list = postService.selectPostList(post);
//        ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
//        return util.exportExcel(list, "岗位数据");
//    }
//
//    /**
//     * 根据岗位编号获取详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:post:query')")
//    @GetMapping(value = "/{postId}")
//    public AjaxResult getInfo(@PathVariable Long postId)
//    {
//        return AjaxResult.success(postService.selectPostById(postId));
//    }
//
//    /**
//     * 新增岗位
//     */
    @PreAuthorize("@ss.hasPermi('system:post:add')")
    @Log(title = "岗位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysPost post)
    {
        if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
        {
            return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败，岗位名称已存在");
        }
        else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
        {
            return AjaxResult.error("新增岗位'" + post.getPostName() + "'失败，岗位编码已存在");
        }
        post.setCreateBy(SecurityUtils.getUsername());
        return toAjax(postService.insertPost(post));
    }
//
//    /**
//     * 修改岗位
//     */
//    @PreAuthorize("@ss.hasPermi('system:post:edit')")
//    @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@Validated @RequestBody SysPost post)
//    {
//        if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post)))
//        {
//            return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败，岗位名称已存在");
//        }
//        else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post)))
//        {
//            return AjaxResult.error("修改岗位'" + post.getPostName() + "'失败，岗位编码已存在");
//        }
//        post.setUpdateBy(SecurityUtils.getUsername());
//        return toAjax(postService.updatePost(post));
//    }
//
//    /**
//     * 删除岗位
//     */
//    @PreAuthorize("@ss.hasPermi('system:post:remove')")
//    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{postIds}")
//    public AjaxResult remove(@PathVariable Long[] postIds)
//    {
//        return toAjax(postService.deletePostByIds(postIds));
//    }
//
//    /**
//     * 获取岗位选择框列表
//     */
//    @GetMapping("/optionselect")
//    public AjaxResult optionselect()
//    {
//        List<SysPost> posts = postService.selectPostAll();
//        return AjaxResult.success(posts);
//    }
}
